package com.dkd.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.dkd.common.annotation.Log;
import com.dkd.common.core.controller.BaseController;
import com.dkd.common.core.domain.AjaxResult;
import com.dkd.common.enums.BusinessType;
import com.dkd.manage.domain.InventoryTransaction;
import com.dkd.manage.service.IInventoryTransactionService;
import com.dkd.common.utils.poi.ExcelUtil;
import com.dkd.common.core.page.TableDataInfo;

/**
 * 库存变动流水记录Controller
 * 
 * @author 赵文楠
 * @date 2025-05-19
 */
@RestController
@RequestMapping("/manage/transaction")
public class InventoryTransactionController extends BaseController
{
    @Autowired
    private IInventoryTransactionService inventoryTransactionService;

    /**
     * 查询库存变动流水记录列表
     */
    @PreAuthorize("@ss.hasPermi('manage:transaction:list')")
    @GetMapping("/list")
    public TableDataInfo list(InventoryTransaction inventoryTransaction)
    {
        startPage();
        List<InventoryTransaction> list = inventoryTransactionService.selectInventoryTransactionList(inventoryTransaction);
        return getDataTable(list);
    }

    /**
     * 导出库存变动流水记录列表
     */
    @PreAuthorize("@ss.hasPermi('manage:transaction:export')")
    @Log(title = "库存变动流水记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InventoryTransaction inventoryTransaction)
    {
        List<InventoryTransaction> list = inventoryTransactionService.selectInventoryTransactionList(inventoryTransaction);
        ExcelUtil<InventoryTransaction> util = new ExcelUtil<InventoryTransaction>(InventoryTransaction.class);
        util.exportExcel(response, list, "库存变动流水记录数据");
    }

    /**
     * 获取库存变动流水记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:transaction:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(inventoryTransactionService.selectInventoryTransactionById(id));
    }

    /**
     * 新增库存变动流水记录
     */
    @PreAuthorize("@ss.hasPermi('manage:transaction:add')")
    @Log(title = "库存变动流水记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InventoryTransaction inventoryTransaction)
    {
        return toAjax(inventoryTransactionService.insertInventoryTransaction(inventoryTransaction));
    }

    /**
     * 修改库存变动流水记录
     */
    @PreAuthorize("@ss.hasPermi('manage:transaction:edit')")
    @Log(title = "库存变动流水记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InventoryTransaction inventoryTransaction)
    {
        return toAjax(inventoryTransactionService.updateInventoryTransaction(inventoryTransaction));
    }

    /**
     * 删除库存变动流水记录
     */
    @PreAuthorize("@ss.hasPermi('manage:transaction:remove')")
    @Log(title = "库存变动流水记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(inventoryTransactionService.deleteInventoryTransactionByIds(ids));
    }
}
